# _*_ coding: utf-8 _*_
import time
import pytest
import allure
from parameterized import parameterized, parameterized_class

import TestCase
from Data.read_yaml import get_success

from Page.CommonPage import CommonPage
from Util.SiWeiUtils import SiWeiUtils
from Operate.BusinessOperate import BusinessOperate
from Maincase.SiWei_Operate import MainCase
from Page.BaseInfo import SiWei_BaseInfo


@allure.feature('TestCase_01:登录验证 ')
@allure.issue('https://market-cloud.ideamake.cn/admin/index.html#/login')
class TestCaseHome01(MainCase):

    # @allure.story('step1:进入登录页面，输入账户密码')
    # @pytest.mark.run(order=11)
    # def test_login_01_1_click_list(self):
    #     try:
    # 写法1 当页面发生改变时使用此写法
    # self.driver.click('xpath=//*[@id="username"]')
    # time.sleep(2)
    # self.driver.send_keys('xpath=//*[@id="username"]', "jinxinran")
    # time.sleep(2)
    # self.driver.click('xpath=//*[@id="password"]')
    # time.sleep(2)
    # self.driver.send_keys('xpath=//*[@id="password"]', "ideamake@8888")
    # time.sleep(2)
    # 对于xpath 可以时手写的，写可以时绝对路径，建议页面元素改变时可以使用绝对路径进行定位
    # self.driver.click('xpath=//*[@id="app"]/div/div/div/div/div[3]/div[1]/form/div[3]/div/div/span/button')
    # self.driver.click('xpath=/html/body/div[1]/div/div/div/div/div[3]/div[1]/form/div[3]/div/div/span/button')
    # time.sleep(2)

    # 写法2 对于页面不变的时使用此写法
    #     text = self.driver.get_inner_ele_text(self.login_page.login_title_text)
    #     time.sleep(2)
    #     self.driver.click(self.login_page.account_input)
    #     time.sleep(2)
    #     self.driver.send_keys(self.login_page.account_input, "jinxinran")
    #     time.sleep(2)
    #     self.driver.click(self.login_page.password_input)
    #     time.sleep(2)
    #     self.driver.send_keys(self.login_page.password_input, "ideamake@8888")
    #     time.sleep(2)
    #     self.driver.click(self.login_page.login_btn)
    #     time.sleep(2)
    #     text1 = self.driver.is_display(self.login_page.login_title_text)
    #     # 断言判断是否成功
    #     assert text == "思为营销云管理平台"
    #     # 这里注意 判断元素是否存在时True和False不可以加引号
    #     assert text1 == False
    # except Exception as e:
    #     raise e
    # finally:
    #     allure.attach(self.driver.get_screenshot_as_base64(), SiWeiUtils.get_current_time(),
    #                   allure.attachment_type.PNG)

    # 数据驱动写法(将完整的运行数据驱动中所有的内容)
    @parameterized.expand(get_success())
    @allure.story('step1:进入登录页面，输入账户密码')
    @pytest.mark.run(order=11)
    def test_login_01_1_click_list(self, name, password):
        try:
            self.driver.click(self.login_page.account_input)
            time.sleep(2)
            self.driver.send_keys(self.login_page.account_input, name)
            time.sleep(2)
            self.driver.click(self.login_page.password_input)
            time.sleep(2)
            self.driver.send_keys(self.login_page.password_input, password)
            time.sleep(2)
            self.driver.click(self.login_page.login_btn)
            time.sleep(2)
        except Exception as e:
            raise e
        finally:
                allure.attach(self.driver.get_screenshot_as_base64(), SiWeiUtils.get_current_time(),
                allure.attachment_type.PNG)
    

if __name__ == '__main__':
    # pass
    pytest.main("-s testcase_siwei_login_01.py")
